home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / util / Exception.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  5.7 KB  |  215 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  Exception.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24.  
  25. if (!IS.isModuleInitialized("IS.NOF.UTIL.Exception"))
  26. {  
  27.     
  28.     /****h* NOF_JavaScript_Library/NOF.UTIL.Exception
  29.     *
  30.     * NAME
  31.     *  NOF.UTIL.Exception
  32.     *
  33.     * DESCRIPTION
  34.     *   Error and exception handling.
  35.     *
  36.     ****/    
  37.     /**
  38.     * Constructor
  39.     * @param msg - identifier of this exception object
  40.     * @param fileName - path to file (or NS-complete class name) from which exception occured.
  41.     * Also, the method name should be added to this argument.
  42.     * @param lineNumber - the line in script
  43.     **/
  44.     function UTIL_Exception( /*String*/ msg, /*String*/ fileName, /*int*/ lineNumber) {
  45.         this.__proto__ = UTIL_Exception.prototype;
  46.         
  47.         this.name = "Exception";
  48.         this.message   = msg;    
  49.         this.fileName    = fileName;
  50.         this.lineNumber    = lineNumber;
  51.     }{
  52.         var method = UTIL_Exception.prototype;
  53.         
  54.         /**
  55.         * Returns the name of the exception.
  56.         **/        
  57.         method.getName = function () { return this.name; }
  58.         
  59.         /**
  60.         * Returns the message of the exception.
  61.         **/        
  62.         method.getMessage =   function () {
  63.             return this.message;
  64.         }
  65.         
  66.         /**
  67.         * Returns the string representation of the exception.
  68.         **/    
  69.         method.toString   =   function () {
  70.             var tmpstr = "[" + this.name + ": " + this.message;
  71.             if (this.fileName != null) {
  72.                 tmpstr += NOF.App.getLineBreak() + " at (" + this.fileName;
  73.                 if (this.lineNumber != null) {
  74.                     tmpstr += ":" + this.lineNumber;
  75.                 }
  76.                 tmpstr += ")";
  77.             }
  78.             tmpstr += "]";
  79.             return tmpstr;
  80.         }
  81.     }
  82.     
  83.     UTIL.__proto__.Exception  = UTIL_Exception;
  84. //TODO: remove it from NOF NS.    
  85.     //NOF.__proto__.Exception  = UTIL.Exception;
  86.     
  87.     /****h* NOF_JavaScript_Library/NOF.UTIL.ChainedException
  88.     *
  89.     * NAME
  90.     *  NOF.UTIL.ChainedException
  91.     *
  92.     * DESCRIPTION
  93.     *  Chained Error and exception handling.
  94.     *
  95.     ****/    
  96.     /**
  97.     * Constructor
  98.     * @param targetE - target Exception 
  99.     * @param msg - identifier of this exception object
  100.     * @param fileName - path to file (or NS-complete class name) from which exception occured
  101.     * @param lineNumber - the line in script
  102.     **/
  103.     function UTIL_ChainedException(/*NOF.UTIL.Exception*/ targetE, /*String*/ msg, /*String*/ fileName, /*int*/ lineNumber) {
  104.         this.__proto__ = UTIL_ChainedException.prototype;            
  105.         this.SUPER(msg, fileName, lineNumber);
  106.         
  107.         this.name = "ChainedException";    
  108.         this.targetException = targetE;                
  109.     }  
  110.     
  111.     UTIL_ChainedException.inherits(NOF.UTIL.Exception)    
  112.     {
  113.         var method = UTIL_ChainedException.prototype;
  114.         method.super_toString =   method.toString;
  115.         method.toString =   function () {
  116.             /*
  117.             var sb = "[";
  118.             sb += this.name + ": msg=";
  119.             sb += this.message;
  120.             if (this.targetException != null)
  121.                 sb += "; targetException=" + this.targetException.getMessage();
  122.             sb += "]";
  123.             return sb;
  124.             */
  125.             var tmpstr = this.super_toString();
  126.             tmpstr = tmpstr.substring(0, tmpstr.length - 1);
  127.             if (this.targetException != null) {
  128.                 tmpstr += "; targetException=" + this.targetException.toString();
  129.             }
  130.             tmpstr += "]";
  131.             return tmpstr;
  132.         }  
  133.         
  134.         method.getMessage =  function () {
  135.             var superMsg = this.message;
  136.             var targetMsg = (this.targetException != null)
  137.                 ? this.targetException.getMessage()
  138.                 : null;
  139.             
  140.             var msg = ((superMsg == null || superMsg.length <= 0)
  141.                 && (targetMsg != null && targetMsg.length > 0))
  142.                 ? targetMsg
  143.                 : superMsg;
  144.             
  145.             if (msg == null || msg.length <= 0) {
  146.                 msg = (this.targetException != null)
  147.                     ? this.targetException.toString()
  148.                     : this.toString();
  149.             }
  150.             
  151.             return msg;
  152.         }
  153.         
  154.         
  155.         method.setTargetException = function (t) {
  156.             this.targetException = t;
  157.         }
  158.         
  159.         method.getTargetException = function () {
  160.             return this.targetException;
  161.         }
  162.         
  163.         method.getRootException =  function () {
  164.             return this.targetException != null ? this.targetException : this;
  165.         }                  
  166.     }
  167.     
  168.     UTIL.__proto__.ChainedException = UTIL_ChainedException;
  169.  
  170.   
  171.     /****h* NOF_JavaScript_Library/NOF.UTIL.ConcurrentModificationException
  172.     *
  173.     * NAME
  174.     *  NOF.UTIL.ConcurrentModificationException
  175.     *
  176.     * DESCRIPTION
  177.     *  Concurrent Modification Error and Exception handling.
  178.     *
  179.     ****/    
  180.     /**
  181.     * Constructor
  182.     **/
  183.     function UTIL_ConcurrentModificationException(/*NOF.UTIL.Exception*/ targetE, /*String*/ msg, /*String*/ fileName, /*int*/ lineNumber) {
  184.         this.__proto__ = UTIL_ConcurrentModificationException.prototype;            
  185.         this.SUPER(msg, fileName, lineNumber);
  186.         
  187.         this.name = "ConcurrentModificationException";            
  188.     }  
  189.     
  190.     UTIL_ConcurrentModificationException.inherits(NOF.UTIL.Exception);        
  191.     UTIL.__proto__.ConcurrentModificationException = UTIL_ConcurrentModificationException;
  192.     
  193.     
  194.     /****h* NOF_JavaScript_Library/NOF.UTIL.AbstractMethodError
  195.     *
  196.     * NAME
  197.     *  NOF.UTIL.AbstractMethodError
  198.     *
  199.     * DESCRIPTION
  200.     *  Concurrent Modification Error and Exception handling.
  201.     *
  202.     ****/    
  203.     /**
  204.     * Constructor
  205.     **/
  206.     function UTIL_AbstractMethodError(/*NOF.UTIL.Exception*/ targetE, /*String*/ msg, /*String*/ fileName, /*int*/ lineNumber) {
  207.         this.__proto__ = UTIL_AbstractMethodError.prototype;            
  208.         this.SUPER(msg, fileName, lineNumber);
  209.         
  210.         this.name = "AbstractMethodError";            
  211.     }  
  212.     
  213.     UTIL_AbstractMethodError.inherits(NOF.UTIL.Exception);        
  214.     UTIL.__proto__.AbstractMethodError = UTIL_AbstractMethodError;
  215. }